<template>
	<view>
		<div class="header">
			<div class="search-box">
				<div class="btn">
					<i class="Ticonfont Ticon-sousuo"></i>
				</div>
				<uni-easyinput primaryColor='#17bf8b' :styles="{'background':'#f1f1f1'}" :inputBorder="false"
					type="text" v-model="data.keywords" placeholder="请输入文章标题" @confirm="keywords" />

			</div>
			<span class="btn2" @click="keywords()">搜索</span>
		</div>
		<div class="lineheight"></div>
		<view class="news-container">
			<view v-for="item in listData" class='news-container-item' @click="toDetail(item)">
				<view class="item-left">
					<view class='top txt-center'>{{ item.year }}</view>
					<view class='bottom txt-center'>{{ `${item.day}/${item.month}` }}</view>
				</view>
				<view class="item-right">
					<view class="item-right-title">
						{{ item.title }}
					</view>
					<view class="item-right-text">
						{{ item.desc }}
					</view>
				</view>
			</view>
		</view>
		<FootTabbar :currentIndex='2' />
	</view>
</template>

<script>
	import FootTabbar from '@/components/foot-tabbar/foot-tabbar.vue'
	export default {
		components: {
			FootTabbar
		},
		data() {
			return {
				// keywords:null,
				listData: [],
				data: {
					size: 10,
					page: 1,
					keywords: null,
					categoryId:10002,
				}
			}
		},
		onLoad() {
			this.getlist()
		},

		methods: {
			getlist() {
				uni.showLoading({
					title: '加载中'
				});
				this.status = 'loading'
				this.$H.post('/article/list', this.data).then(res => {
					this.status = 'loadmore'
			
					uni.hideLoading();
			
					res.data.list.data.forEach(item => {
						this.listData.push(item);
					});
					
					this.listData.forEach((item) => {
						if (item.create_time !== '') {
							item.year = item.create_time.substring(0, 4)
							item.month = item.create_time.substring(5, 7)
							item.day = item.create_time.substring(8, 10)
						}
					})
					this.data.page++;
				})
			},
			//请求列表
			getlists() {
/* 				let obj = [{
					id: 31,
					title: "新闻标题",
					content: '新闻内容新闻内容新闻内容新闻内容新闻内容新闻内容新闻内容',
					videoUrl: null,
					videoFullUrl: "https://huizhou.kunsung.com.cn:9875/null",
					videoName: null,
					coverUrl: "group1/M00/07/FF/wKg8lmWCrNeARPxoAAcUHP1mPt4266.png",
					coverFullUrl: "https://huizhou.kunsung.com.cn:9875/group1/M00/07/FF/wKg8lmWCrNeARPxoAAcUHP1mPt4266.png",
					createTime: "2023-10-07 14:15:47",
				}, {
					id: 31,
					title: "新闻标题",
					content: '新闻内容新闻内容新闻内容新闻内容新闻内容新闻内容新闻内容',
					videoUrl: null,
					videoFullUrl: "https://huizhou.kunsung.com.cn:9875/null",
					videoName: null,
					coverUrl: "group1/M00/07/FF/wKg8lmWCrNeARPxoAAcUHP1mPt4266.png",
					coverFullUrl: "https://huizhou.kunsung.com.cn:9875/group1/M00/07/FF/wKg8lmWCrNeARPxoAAcUHP1mPt4266.png",
					createTime: "2023-10-07 14:15:47",
				}, ]
				obj.forEach((item) => {
					if (item.createTime !== '') {
						item.year = item.createTime.substring(0, 4)
						item.month = item.createTime.substring(5, 7)
						item.day = item.createTime.substring(8, 10)
					}
				})
				this.listData = obj */
			},
			// 关键词搜索
			keywords() {
				this.data.page = 1;
				this.listData = [];
				this.getlist();
			},

			toDetail(item) {
				uni.navigateTo({
					url: '/pages/news/news-ds?id=' + item.article_id
				})
			},
			onReachBottom() {
				this.getlist();
			},
		},

	}
</script>

<style scoped lang="scss">
	page {
		background: rgba(248, 248, 248, 1);
	}

	.lineheight {
		height: 110rpx;
	}

	.header {
		position: fixed;
		top: 0px;
		left: 0px;
		width: 100%;
		padding: 0px 30rpx;
		padding-bottom: 40rpx;
		background: #17bf8b;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		color: #fff;

		.btn2 {
			margin-left: 10rpx;
		}
	}

	.news-container {
		margin: 28rpx 0;
		background: #fff;
		box-shadow: 0rpx 0rpx 52rpx 0rpx rgba(4, 0, 0, 0.12);
		border-radius: 16rpx;

		&-item {
			padding: 40rpx 30rpx;
			border-bottom: 2rpx solid #F4F4F4;
			overflow: hidden;
			display: flex;

			.item-left {
				width: 96rpx;
				height: 112rpx;
				text-align: center;

				.top {
					width: 100%;
					height: 60rpx;
					line-height: 60rpx;
					font-size: 29rpx;
					background: #F8F8F8;
					color: #078DA3;
					border-radius: 10rpx 10rpx 0 0;
				}

				.bottom {
					width: 100%;
					height: 52rpx;
					line-height: 52rpx;
					font-size: 22rpx;
					color: #333333;
					background: #D0E4E6;
					border-radius: 0 0 10rpx 10rpx;
				}
			}

			.item-right {
				margin-left: 28rpx;
				width: 80%;
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				&-title {
					flex: 1;
					font-size: 32rpx;
					font-weight: bold;
					color: #333333;
					line-height: 56rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}

				&-text {
					flex: 1;
					height: 56rpx;
					font-size: 27rpx;
					font-weight: 400;
					color: #333333;
					line-height: 56rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;

				}
			}
		}
	}

	.search-box {
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		// border: 1px solid rgba(23, 191, 139, 1);
		padding: 0px 5px;
		margin: 10rpx 0px;
		overflow: hidden;
		flex-grow: 1;
		// background-color: rgba(255, 255, 255, 0.3);
		background: #f1f1f1;
		// color: #fff;

		// width: 100%;
		input {
			background: none;
		}
	}
</style>